﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinesys.Entities;
using Chinesys.DataModel;
using Chinesys.Domain.DataMapper;

namespace Chinesys.Domain
{
    public static class SubCategoryDomain
    {
        public static List<SubCategoryEntity> GetByCategory(int categoryId)
        {
            List<SubCategoryEntity> list;

            using (ChinesysEntities db = new ChinesysEntities())
            {
                List<CategorySubcategory> result = (from o in db.CategorySubcategories
                                                    where o.CategoryId == categoryId
                                                    select o).ToList();
                if (result.Any())
                {
                    list = new List<SubCategoryEntity>();

                    result.ForEach(x => list.Add(SubCategoryDataMapper.SubCategoryFromRowToEntity(x.SubCategory)));
                }
                else
                    list = null;
            }

            return list;
        }
    }
}
